<template>
  <div>
    <el-table class="table_el" :data="VmList" style="width: auto">
      <el-table-column label="ID" prop="id" />
      <el-table-column label="购买价格" prop="pay" />
      <el-table-column label="购买时间">
        <template #default="scope">
          {{ scope.row.created_at }}
        </template>
      </el-table-column>
      <el-table-column label="到期时间">
        <template #default="scope">
          {{ scope.row.become_time }}
        </template>
      </el-table-column>
      <el-table-column label="所属套餐" prop="plan_id" />
      <el-table-column label="用户ID" prop="user_id" />
      <el-table-column label="状态">
        <template #default="scope">
          <el-tag :type="scope.row.state == 0 || scope.row.state == 1
              ? 'info'
              : scope.row.state == 2
                ? 'success'
                : 'danger'
            ">{{
              scope.row.state == 0
                ? "未支付"
                : scope.row.state == 1
                  ? "未开通"
                  : scope.row.state == 2
                    ? "开机"
                    : "关机"
            }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column width="230">
        <template #header>
          <el-input v-model="containerBox.key" size="small" placeholder="关键字筛选" />
        </template>
        <template #default="scope">
          <el-button size="small"><router-link
              :to="'/servers/virtualInfo?container_id=' + scope.row.id">管理</router-link></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <div class="m-t-20px">
      <el-pagination background layout="prev, pager, next,sizes" :total="total" :current-page="containerBox.page"
        :page-size="containerBox.count" :page-sizes="[1, 5, 10]" @update:current-page="handleCurrentPageChange"
        @update:page-size="handlePageSizeChange" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted, defineProps, onBeforeUnmount } from "vue";
import { getVirtualList } from "@/api/virtual";
const props = defineProps(["ID"]);

onMounted(async () => {
  await GetList();
});

const VmList = ref([]);
const total = ref(0);
const containerBox = reactive({
  key: "",
  page: 1,
  count: 10,
  server_id: props.ID
});

// 获取虚拟机列表
const GetList = async () => {
  const res = await getVirtualList(containerBox);
  console.log(res);
  if (res.data.code == 200) {
    VmList.value = res.data.data;
    total.value = res.data.count;
  }
};

// 分页
const handleCurrentPageChange = (val: number) => {
  containerBox.page = val;
  GetList();
};
const handlePageSizeChange = (val: number) => {
  containerBox.count = val;
  GetList();
};
</script>

<style scoped></style>
